<?php
/**
 * Représente un type d'unité
 */
class SW_Unit
{
	/** @var mixed */
	protected $group;

	/** @var int */
	protected $count;

	/**
	 * @param mixed $group
	 * @param int $count
	 */
	public function __construct($group, $count)
	{
		$this->group = $group;
		$this->setCount($count);
	}

	/**
	 * @param int $count
	 */
	public function setCount($count)
	{
		$count = (int)$count;
		$this->count = ($count < 1) ? 0 : $count;
	}

	/**
	 * @return int
	 */
	public function getCount()
	{
		return $this->count;
	}

	/**
	 * @param int $maxCount
	 */
	public function maxCount($countMax)
	{
		if ($this->count > $countMax)
			$this->setCount($countMax);
	}

	/**
	 * @return mixed
	 */
	public function getGroup()
	{
		return $this->group;
	}

	/**
	 * @param int
	 */
	public function add($unity)
	{
		$this->count += $unity;
	}

	/**
	 * @param int
	 */
	public function subtract($unity)
	{
		$this->count -= $unity;
		if ($this->count < 0)
			$this->count = 0;
	}
}